package com.sunday.common.core.remoting.base.response.core;

import java.util.Arrays;

/**
 * 异常过滤器
 *
 * @author zsy
 * @since 2022/10/14
 */
@FunctionalInterface
public interface ThrowableFilter {

    /**
     * 缺省过滤
     * 需要被记录为结果未知的异常类型列表.
     */
    ThrowableFilter DEFAULT_FILTER = f -> true;

    boolean matches(Throwable error);

    static ThrowableFilter multiple(Class<? extends Throwable>... recordExceptions) {
        return error -> Arrays.stream(recordExceptions).anyMatch(clazz -> clazz.isInstance(error));
    }

}